<template>
  <div>
    <el-dialog
      title="测试"
      :visible.sync="open"
      width="60%"
      :before-close="close"
    >
      <div>
        <v-form-render ref="vFormRef" :option-data="optionData">
        </v-form-render>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { workflowForm } from "@/api/app/electronicForms.js";
export default {
  name: "testModel",
  props: {
    open: {
      type: Boolean,
      default: false,
    },
    close: {
      type: Function,
      default: () => {},
    },
    row: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      optionData: {},
    };
  },

  async mounted() {
    const res = await workflowForm(this.row.id);
    if (res.code == 200 && res.data?.formConfig && res.data?.widgetList) {
      let formJson = {
        formConfig: JSON.parse(res.data?.formConfig),
        widgetList: JSON.parse(res.data?.widgetList),
      };
    //   const dictArr = [];
    //   const dictUrl = [];
    //   JSON.parse(res.data?.widgetList).forEach((item) => {
    //     if (item.options?.dictUrl) {
    //       dictArr.push({
    //         name: item.options.name,
    //         dictUrl: item.options.dictUrl,
    //       });
    //       dictUrl.push(item.options.dictUrl)
    //     }
    //   });
    //   const dictFun = async () => {
    //    this.getDicts(dictUrl.toString()).then((response) => {
    //         const res = response.data;
    //         res.forEach((val) => {
    //           val.label = val.dictLabel;
    //           val.value = val.dictValue;
    //         });
    //         this.optionData[dictArr?.[0]?.name] = res;
    //       });
    //     return true;
    //   };
    //   await dictFun();
    this.$refs.vFormRef.setFormJson(formJson);
    } else {
      this.$message.error("请先设计表单");
    }
  },

  methods: {},
};
</script>

<style lang="scss" scoped>
</style>